////////////////////////////////////////
// StringTable.cpp
// Name:  Stephen Durfey
// Class: CS335
// Time:  Tue, Thurs 1:00-2:15pm
// Professor: Dr. Michael Poor

#include "StringTable.h"
#include <string>

using namespace std;

////////////////////////////////////////
// This constructor creates the entire 2d string vector
// that will hold all information about the cities described
// in the file specified by the user at the command line prompt. 

StringTable::StringTable(ifstream & inFile, string &fullWord)
{
    bool notEndOfLine = true;
    bool notEndOfFile = true;
    vector <string> vectLine;  //stores the contents of each line of the file
    
    while(notEndOfFile)  //checks for end of file
    {
        notEndOfLine = true;
        
        while(notEndOfLine) //loops until end of a line
        {
            notEndOfLine = readMultiWord(fullWord, inFile, sep); 
       
            //if the end of the line has not been encountered yet, push fullWord
            //into the string vector, vectLine.
            if(notEndOfLine) 
                vectLine.push_back(fullWord);
        }
        
        
        //once loops exits, it indicates an end of line, and pushes back
        //vectLine, which contains the info for each line of the file.
        vectMatrix.push_back(vectLine);
        
        //clears vectLine to ensure the next push_back()
        //is only 1 line in length, rather than multiple
        //which is what would happen if it was not cleared.
        vectLine.clear();  
        
        
        //checks to see if the next line to be read begins with a "#". if it does
        //outer while loop quits constructor. If not, the word created is pushed
        //back onto the vectLine string vector.
        notEndOfFile = readMultiWord(fullWord, inFile, sep); 
        
        if(notEndOfFile)
            vectLine.push_back(fullWord);
           
    }
}

//returns the number of rows in the 2d string vector
int StringTable::rows() const
{
    return vectMatrix.size();
}



// TODO: Overload the [] operator for this class.
//returns a reference to the vector row. Without "&", the function
//returns a value, which would cause compile errors when it is used 
//in the file "StringTableTester.cpp"

vector<string>& StringTable::operator[](int index)
{
    return vectMatrix[index];
}


